﻿Imports DotNetNuke.Entities.Modules
Imports System.Web.UI.WebControls
Imports DotNetNuke.Framework
Imports Telerik.Web.UI

Namespace DotNetNuke.Modules.ActiveForums.Controls
    Public Class ForumEditor
        Inherits PortalModuleBase

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            jQuery.RequestDnnPluginsRegistration()

            BindForums()
        End Sub
        Private Sub BindForums()
            Using dr As IDataReader = DataProvider.Instance.Forums_List(PortalId, ModuleId, -1, -1, False)
                ctlForums.Nodes.Clear()
                Dim dt As New DataTable("Forums")
                Dim row As DataRow = Nothing
                dt.Load(dr)
                dr.Close()

                Dim groupNode As New RadTreeNode()
                Dim strParent As String = "-1"



                Dim totalGroupForum As Integer = 0
                Dim tmpGroup As String = String.Empty
                Dim i As Integer = 0
                Dim groupCount As Integer = 0
                Dim forumCount As Integer = 0
                Dim hasChildren As Boolean = False
                For Each row In dt.Rows
                    If tmpGroup <> row("ForumGroupId").ToString() Then
                        If hasChildren Then
                            ctlForums.Nodes.Add(groupNode)
                            hasChildren = False
                        End If
                        drpForums.Items.Add(New ListItem(row("GroupName").ToString(), row("ForumGroupId").ToString()))
                        groupNode = New RadTreeNode()
                        groupNode.Text = row("GroupName").ToString()
                        groupNode.Value = row("ForumGroupId").ToString()
                        tmpGroup = row("ForumGroupId").ToString()
                    End If
                    drpForums.Items.Add(New ListItem("-----" & row("ForumName").ToString(), row("ForumId").ToString()))
                    Dim node As New RadTreeNode
                    node.Text = row("ForumName").ToString()
                    node.Value = row("ForumId").ToString()
                    groupNode.Nodes.Add(node)
                    hasChildren = True
                Next
                ctlForums.Nodes.Add(groupNode)
            End Using

        End Sub
    End Class
End Namespace
